import 'package:flutter/foundation.dart';
import 'package:flutter_flame/config/GameConfig.dart';
import 'package:flutter_flame/worlds/game/model/SeedModel.dart';

@immutable
class GameStatesState {
  final double money; // 金币
  final double sunlight; // 当前收集的阳光
  final bool isGameOver; // 游戏是否结束
  final SeedModel? selectedPlant; // 当前选中的植物
  final int zombieTimes; // 僵尸轮次（每隔30秒，增加僵尸的数量）
  final List<double> zombiePeriods; // 僵尸放置间隔

  const GameStatesState({
    required this.money,
    required this.sunlight,
    required this.isGameOver,
    required this.selectedPlant,
    required this.zombieTimes,
    required this.zombiePeriods,
  });

  // 初始状态
  factory GameStatesState.initial() {
    return GameStatesState(
      money: 100000,
      sunlight: GameConfig.isDebug ? 1000 : 50,
      isGameOver: false,
      selectedPlant: null,
      zombieTimes: 0,
      zombiePeriods: GameConfig.isDebug ? [1] : [12, 8, 6, 4, 2],
    );
  }

  // 复制并更新指定字段
  GameStatesState copyWith({
    double? money,
    double? sunlight,
    bool? isGameOver,
    SeedModel? selectedPlant,
    int? zombieTimes,
    List<double>? zombiePeriods,
  }) {
    return GameStatesState(
      money: money ?? this.money,
      sunlight: sunlight ?? this.sunlight,
      isGameOver: isGameOver ?? this.isGameOver,
      selectedPlant: selectedPlant ?? this.selectedPlant,
      zombieTimes: zombieTimes ?? this.zombieTimes,
      zombiePeriods: zombiePeriods ?? this.zombiePeriods,
    );
  }
}
